package com.dwjm.exam.stu_reg;

import com.dwjm.exam.pojo.Student;
import com.dwjm.exam.utils.CommonResult;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/reg")
public class StudentRegisterHandler extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置编码方式
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //获取浏览器传递过来的参数，登录账号和密码
        String username=req.getParameter("username");
        String password = req.getParameter("password");
        Student student=new Student();
        student.setUsername(username);
        student.setPassword(password);
        StudentRegisterDao studentRegisterDao = new StudentRegisterDaoImpl();
        boolean b = studentRegisterDao.registerStudent(student);
        if (b) {
            resp.getWriter().write("Y");
        } else {
            resp.getWriter().write("N");
        }
    }
}
